// import proFetch from "../../../../../public/functions/project-fetch";
import {hrAjax as ajax} from 'src/hrpub/common/utils/utils';
import updateButtonStatus from "./updateButtonStatus";
import {cacheTools, toast} from 'nc-lightapp-front';
import getOneAgreementInfo from "./getOneAgreementInfo";
import handleAllpks from "../../../../finish/main/container/functions/handleAllpks";

export default function saveAgreementData() {
    const {isRefer, agreementType, editPk, json} = this.state;
    let cardId = "agreementCard";
    const agreementData = this.props.form.getAllFormValue(cardId, true);
    return ajax({
        url: '/nccloud/hrcm/agreement/ChangeSaveAction.do',
        body: {
            agreementData: {
                agreementData: agreementData,
            },
            agreementType: agreementType,
            isRefer: isRefer
        },
    }).then((res) => {
        let oldEditPk = editPk;
        if (res.success) {
            if (isRefer) {
                this.setState({
                    isEdit: false,
                    editPk: this.refs.header.props.cardPagination.getNextCardPaginationId({id: editPk, status: 1}),
                }, () => {
                    handleAllpks.remove(oldEditPk);// 更新卡片分页主键
                    this.updateState({
                        btnCode: 'save',
                        pageFlag: 'card',
                        isEdit: false
                    });
                    toast({color: 'success', content: json['cm6011-000136']}) //保存并生效成功！
                })
            } else {
                this.setState({
                    isEdit: false
                }, () => {
                    this.updateState({
                        btnCode: 'save',
                        pageFlag: 'card',
                        isEdit: false
                    });
                });
                toast({color: 'success', content: json['cm6011-000005']}) //保存成功！
            }
            // getOneAgreementInfo.call(this);
            updateButtonStatus.call(this, this.state.orgVal, this.state.agreementType, false);
        }
    });
}
